//https://leetcode.cn/problems/rotate-array/description/
//轮转数组
//给定一个整数数组 nums，将数组中的元素向右轮转 k 个位置，其中 k 是非负数。

void reverse(int* nums, int left, int right)
{
    while(left < right)
    {
        int tmp = nums[right];
        nums[right] = nums[left];
        nums[left] = tmp;
        left++;
        right--;
    }
}
//1
void rotate(int* nums, int numsSize, int k) {
    k %= numsSize;
    reverse(nums, 0, numsSize - k - 1);
    reverse(nums, numsSize - k, numsSize - 1);
    reverse(nums, 0, numsSize - 1);
}

//2
void rotate(int* nums, int numsSize, int k) {
    k = k % numsSize;
    if(k == 0)
    return;
    int nums_x[k];
    for(int i = 0; i < k; i++)
    {
        int p = i;
        while(p < numsSize){p += k;}
        nums_x[p % numsSize] = nums[p - k];
        p = p - k;
        while(p >= k)
        {
            nums[p] = nums[p - k];
            p = p - k;
        }
    }
    for(int i = 0; i < k; i++)
    {
        nums[i] = nums_x[i];
    }
}